package com.example.administrator.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.administrator.myapplication.uilts.PeiZhiActivity;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by 董豪华 on 2017/1/6.
 */
public class TomorrowAcitivity extends AppCompatActivity {
    private TextView nameming;
    private TextView datetimming;
    private TextView summaryming;
    private TextView allming;
    private TextView colorming;
    private TextView healthming;
    private TextView loveming;
    private TextView moneyming;
    private TextView numberming;
    private TextView QFriendming;
    private TextView workming;
    String xingzuo;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tomorrowxingzuo_item);
        Intent intent = getIntent();
        xingzuo = intent.getStringExtra("xingzuo");
        innitdata();
        shujufanhui(xingzuo);
    }
    public void shujufanhui(String consName){
        String url = "http://web.juhe.cn:8080/constellation/getAll?consName="+consName+"&type=tomorrow&key=4ab3d0b2232c72d9c3dc4747baf8cf4f";
        StringRequest request = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
               jieximing (response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        PeiZhiActivity.mrequestQueue.add(request);
    }
    /*今日或明日*/
    public void jieximing(String response){
        try {
            JSONObject jsonObject = new JSONObject(response);
            String name1 = jsonObject.optString("name");/*星座名称*/
            String datetime1 = jsonObject.optString("datetime");/*日期*/
            String date = jsonObject.optString("date");
            String all1 = jsonObject.optString("all");/*综合指数*/
            String color1 = jsonObject.optString("color");/*幸运色*/
            String health = jsonObject.optString("health");/*健康指数*/
            String love = jsonObject.optString("love");/*爱情指数*/
            String money = jsonObject.optString("money");/*财运指数*/
            String number = jsonObject.optString("number");/*幸运数字*/
            String qFriend = jsonObject.optString("QFriend");/*速配星座*/
            String summary1 = jsonObject.optString("summary");/*今日概述*/
            String work = jsonObject.optString("work");/*工作指数*/
            String error_code = jsonObject.optString("error_code");/*返回码*/
            nameming.setText(name1);
            datetimming.setText(datetime1);
            summaryming.setText(summary1);
            allming.setText("综合指数:"+all1);
            colorming.setText("幸运色:"+color1);
            healthming.setText("健康指数:"+health);
            loveming.setText("爱情指数:"+love);
            moneyming.setText("财运指数:"+money);
            numberming.setText("幸运数字:"+number);
            QFriendming.setText("速配星座:"+qFriend);
            workming.setText("工作指数"+work);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    private void innitdata() {
        nameming = (TextView) findViewById(R.id.nameming);
        datetimming = (TextView) findViewById(R.id.datetimming);
        summaryming = (TextView) findViewById(R.id.summaryming);
        allming = (TextView) findViewById(R.id.allming);
        colorming = (TextView) findViewById(R.id.colorming);
        healthming = (TextView) findViewById(R.id.healthming);
        loveming = (TextView) findViewById(R.id.loveming);
        moneyming = (TextView) findViewById(R.id.moneyming);
        numberming = (TextView) findViewById(R.id.numberming);
        QFriendming = (TextView) findViewById(R.id.QFriendming);
        workming = (TextView) findViewById(R.id.workming);
    }
}
